package framework.mybatis.xml;

import framework.mybatis.xml.dao.UserDao;
import framework.mybatis.xml.entity.User;
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;

/**
 * 基于 namespace 的方法调用（不推荐）
 *
 * @author ME
 */
public class XmlConfigTest {

    UserDao dao = new UserDao();

    @Test
    public void testSelect() throws IOException {
        // dao.createTable();

        User u1 = new User(999);
        dao.delete(u1);

        User user = new User(999, "Lucy", 14);
        int result = dao.insert(user);
        Assert.assertEquals("插入 1行",
                1, result);

        System.out.println("insert User[999]: " + dao.getUser(user));
        System.out.println("UserVO: " + dao.getUserVO(user));

        user.setAge(17);
        result = dao.update(user);
        Assert.assertEquals("更新 1行",
                1, result);
        System.out.println("update User[999]: " + dao.getUser(user));

        result = dao.delete(user);
        Assert.assertEquals("删除 1行",
                1, result);
        System.out.println("delete User[999]: " + dao.getUser(user));
    }

}
